/*
package com.jason.campusinn.service;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;

import com.jason.campusinn.R;
import com.jason.campusinn.utils.CommonMethodUtils;
import com.jason.campusinn.utils.FileUtil;
import com.jason.campusinn.utils.HttpUtil;
import com.jason.campusinn.utils.LogUtil;
import com.jason.campusinn.utils.SharedPreferenceUtil;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import java.io.File;

public class VersionUpdateService extends Service {
    private static final String TAG = "UpdateService";
    private Context mContext;
    private NotificationManager mNotificationManager;
    private NotificationCompat.Builder mNotifyBuilder;
    private ProgressDialog mDialog;
    */
/**
     * 新版本号
     *//*


    private String versionName = "";

    */
/**
     * 下载地址
     *//*


    private String downloadUrl = "";


    */
/**
     * apk存储根目录
     *//*


    private String filePath = "";

    */
/**
     * apk文件名
     *//*


    private String fileName = "wanna";
    private HttpHandler<File> handler;

    public VersionUpdateService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;

    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
    }

//    @Override
//    public int onStartCommand(Intent intent, int flags, int startId) {
//
//        mDialog = new ProgressDialog(UpdateDialogActivity.updateContext);
//        mDialog.setTitle("版本升级");
//        mDialog.setMessage("正在下载");
//        mDialog.setIcon(R.drawable.icon_logo_small);
//        mDialog.setIndeterminate(false);
//        mDialog.setCancelable(false);
//        mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//        mDialog.setProgress(100);
//
//
//        flags = START_NOT_STICKY;
//        filePath = getApkSavePath();
//        SharedPreferenceUtil.setSharedlongData(mContext, "start_time", System.currentTimeMillis());
//        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
////		setForeground(false);
//        mNotificationManager.cancel(0);
//        if (intent == null) {
//            return super.onStartCommand(intent, flags, startId);
//        }
//        if (intent.hasExtra("version_name")) {
//            versionName = intent.getStringExtra("version_name");
//            fileName = "wanna" + versionName + ".apk";
//        }
//        if (intent.hasExtra("url")) {
//            downloadUrl = intent.getStringExtra("url");
//            startDownload(downloadUrl);
//        }
//        return super.onStartCommand(intent, flags, startId);
//    }



//    @SuppressWarnings("unchecked")
//    private void startDownload(String url) {
//        LogUtil.d("download : url = " + url);
//
//        handler = HttpUtil.downloadFile(url, filePath + "/" + fileName, true,
//                new RequestCallBack<File>() {
//
//                    @Override
//                    public void onStart() {
//                        super.onStart();
//                        showNotification();
//                        if (mDialog != null) {
//                            mDialog.show();
//                        }
//                    }
//
//                    @Override
//                    public void onLoading(long total, long current,
//                                          boolean isUploading) {
//                        super.onLoading(total, current, isUploading);
//                        int progress = Math.round((current * 100) / total);
//                        mNotifyBuilder.setOngoing(true);
//                        mNotifyBuilder.setProgress(100, progress, false);
//                        mNotifyBuilder.setContentText("下载：" + progress + "%");
//                        mNotificationManager.notify(0, mNotifyBuilder.build());
//
//                        mDialog.setProgress(progress);
//                    }
//
//                    @Override
//                    public void onSuccess(ResponseInfo<File> arg0) {
//                        if (mDialog != null && mDialog.isShowing()) {
//                            mDialog.dismiss();
//                        }
//                        File file = new File(filePath, fileName);
//                        CommonMethodUtils.OpenApkFile(mContext, file);
//                        mNotifyBuilder.setContentText("下载完成");
//                        mNotificationManager.cancel(0);
//                        LogUtil.d(TAG + "version update is done");
//                        stopSelf();
//                    }
//
//                    @Override
//                    public void onFailure(HttpException arg0, String arg1) {
//                        if (mDialog != null && mDialog.isShowing()) {
//                            mDialog.dismiss();
//                        }
//                        LogUtil.e(TAG + arg0.toString());
//                        if (arg0.getExceptionCode() == HttpUtil.FILE_DOWNLOAD_EXCEPTION_CODE
//                                && HttpUtil.FILE_DOWNLOAD_COMPLETE.equals(arg1)) {// 本地已有该文件
//                            File file = new File(filePath, fileName);
//                            CommonMethodUtils.OpenApkFile(mContext, file);
//                            mNotificationManager.cancel(0);
//                            mNotifyBuilder.setAutoCancel(true);
//                            stopSelf();
//                            return;
//                        }
//                        if (!FileUtil.isSDCardExist()) {
//                            Toast.makeText(mContext, "下载失败,请检查SD卡是否存在", Toast.LENGTH_SHORT).show();
//                        }
//
//                        if (!FileUtil.isHasAvailableMemory()) {
//                            Toast.makeText(mContext, "下载失败,SD卡内存不足", Toast.LENGTH_SHORT).show();
//                        }
//                        mNotifyBuilder.setContentText("下载失败");
//                        mNotifyBuilder.setAutoCancel(true);
//                        mNotificationManager.notify(0, mNotifyBuilder.build());
//                        stopSelf();
//                    }
//
//                });
//    }

    @Override
    public void onDestroy() {
        if (mNotificationManager != null) {
            mNotificationManager.cancelAll();
        }
        if (handler != null) {
            handler.cancel();
        }
        stopSelf();
        super.onDestroy();
    }

//    private void showNotification() {
//        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        Intent intent = new Intent();
//        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
//                intent, 0);
//
//        mNotifyBuilder = new NotificationCompat.Builder(this);
//        mNotifyBuilder.setSmallIcon(R.drawable.icon_logo_small);
//        mNotifyBuilder.setDefaults(4);
//        mNotifyBuilder.setTicker("正在下载新版本...");
//        mNotifyBuilder.setContentIntent(pendingIntent);
//        mNotifyBuilder.setContentTitle(getString(R.string.app_name));
//        mNotifyBuilder.setContentText("下载新版本");
//        mNotifyBuilder.setAutoCancel(true);
//        mNotificationManager.notify(0, mNotifyBuilder.build());
//    }

    private String getApkSavePath() {
        String path = Environment.getExternalStorageDirectory().toString()
                + File.separator + "yellowpages" + File.separator + "apk";
        File picFile = new File(path);
        if (!picFile.exists()) {
            picFile.mkdirs();
        }
        return path;
    }
}

*/
